public class ReverseLinkedList {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode cur = head;

        while (cur != null) {
            ListNode next = cur.next;
            cur.next = prev;
            prev = cur;
            cur = next;
        }

        return prev;
    }

    public ListNode reverseRange(ListNode head, int m, int n) {
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        ListNode prev = dummyHead;

        for (int i = 1; i < m; i++) {
            prev = prev.next;
        }
        ListNode mNode = prev.next;
        ListNode cur = mNode.next;

        for (int i = 0; i < n - m; i++) {
            mNode.next = cur.next;
            cur.next = prev.next;
            prev.next = cur;
            cur = mNode.next;
        }

        return dummyHead.next;
    }

    public ListNode deleteDuplicates(ListNode head) {
        ListNode prev = null;
        ListNode cur = head;
        while (cur != null) {
            if (prev != null && prev.val == cur.val) {
                prev.next = cur.next;
                cur = prev.next;
            } else {
                prev = cur;
                cur = cur.next;
            }
        }
        return head;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 5, 6, 6};
        ListNode head = new ListNode(nums);
        System.out.println(head);

//        ListNode res = (new ReverseLinkedList()).reverseList(head);
//        System.out.println(res);

//        ListNode resRange = (new ReverseLinkedList()).reverseRange(head, 2, 5);
//        System.out.println(resRange);

        ListNode resRange = (new ReverseLinkedList()).deleteDuplicates(head);
        System.out.println(resRange);
    }
}
